import java.util.Arrays;

import info.gridworld.actor.Bug;

/**
 * A <code>DancingBug</code> traces out a  "dancing" of a given turns. <br /> */
public class DancingBug extends Bug
{
    private int steps;
    private int[] turnList;
    /**
     * Constructs a dancing bug that traces a "dancing" of a given turns
     * @param dancing turns
     */
    public DancingBug(int[] turns)
    {
    	if (turns != null)
    		turnList = Arrays.copyOf(turns, turns.length);
        steps = 0;
    }

    /**
     * Moves to the next location of the "dancing".
     */
    public void act()
    {
        if (steps == turnList.length)
        {
        	steps = 0;
        }
        for (int i = 0; i < turnList[steps]; i++)
        {
        	turn();
        }
        steps++;
        super.act();
    }
}
